package com.gtxc.kotlinmvvm.ui.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;

import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.aleyn.mvvm.base.BaseActivity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.drake.statusbar.StatusBarKt;
import com.gtxc.kotlinmvvm.BR;
import com.gtxc.kotlinmvvm.R;
import com.gtxc.kotlinmvvm.adapater.MyFenSiAdapater;
import com.gtxc.kotlinmvvm.adapater.NewsConsultingAdapater;
import com.gtxc.kotlinmvvm.databinding.ActivityNewsConsultingBinding;

import com.gtxc.kotlinmvvm.network.request.TitlBeanItem;
import com.gtxc.kotlinmvvm.viewmodle.NewsConsultingViewModle;

import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

/**
 * FileName:NewsConsultingActivity
 * Author：Administrator
 * Date:2021 2021/9/28 21:01
 * Copyright (C), 2020-2021,成都拇音科技有限公司
 * <p>
 * <p>
 * Description: zwl
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
//新闻资讯
public class NewsConsultingActivity extends BaseActivity<NewsConsultingViewModle, ActivityNewsConsultingBinding> {
    private List<String> lists=new ArrayList<>();
    private NewsConsultingAdapater adapter;
    @Override
    public int layoutId() {
        return R.layout.activity_news_consulting;
    }

    @Override
    public void initView(@Nullable Bundle savedInstanceState) {
        StatusBarKt.immersive(this, getResources().getColor(R.color.white), true);
        getMBinding().toolbar.setTitleBackgroundColor(Color.WHITE);
        getMBinding().toolbar.setLeftBackgroundColor(R.mipmap.left_back);
        getMBinding().toolbar.setOnLeftClickListener(v -> finish());
    }

    @Override
    public void initData() {

        LinearLayoutManager manager =new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        getMBinding().listRecyclerView.setLayoutManager(manager);
        adapter =new NewsConsultingAdapater(R.layout.news_consulting_itm);
        viewModel.getListTitlis().observe(this, new Observer<List<TitlBeanItem>>() {
            @Override
            public void onChanged(List<TitlBeanItem> titlBeanItems) {
                //注册观察者,观察数据的变化
                Log.i("TAG", "onChanged: wedwedwede:"+titlBeanItems.size());
                for (int i = 0; i <titlBeanItems.size() ; i++) {
//                    lists.add(titlBeanItems.get(i).getTitle());
                    adapter.setList(titlBeanItems);
                }
            }
        });
        adapter.addChildClickViewIds(R.id.re_01);
        adapter.setOnItemChildClickListener((adapter, view, position) -> {
            Log.i("ferfrfrf", "initDaededeta: "+position);
            Intent intent=new Intent(NewsConsultingActivity.this,NewsDetailsActivity.class);
            intent.putExtra("id",position+1);
            startActivity(intent);

        });
        getMBinding().listRecyclerView.setAdapter(adapter);
    }

    @Override
    public void initCLick() {


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public int variableID() {
        return BR.NewsConsultingViewModle;
    }

    @Override
    public void bindViewModel() {

    }
}
